package com.youbug.mall.pms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.common.config.valid.SelectGroup;
import com.youbug.common.vo.QueryVo;
import com.youbug.common.vo.R;
import com.youbug.mall.pms.entity.PmsBrand;
import com.youbug.mall.pms.service.IPmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 品牌 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-07-04
 */
@RestController
@RequestMapping("/pms-brand")
public class PmsBrandController {

    @Autowired
    private IPmsBrandService pmsBrandService;

    @PostMapping("/getPmsBrands")
    public R<IPage<PmsBrand>> getPmsBrands(@Validated(SelectGroup.class) @RequestBody QueryVo<PmsBrand> queryVo){

        IPage<PmsBrand> userPage = pmsBrandService.getPmsBrands(queryVo);

        return R.ok(userPage);
    }

    @GetMapping("/changeShowStatus/{brandId}/{status}")
    public R<Boolean> changeShowStatus(@PathVariable Long brandId, @PathVariable Integer status){

        Boolean update =  pmsBrandService.changeShowStatus(brandId, status);

        return R.ok(update);
    }

    @GetMapping("/getPmsBrand/{id}")
    public R<PmsBrand> getUser(@PathVariable String id){

        PmsBrand brand = pmsBrandService.getById(id);

        return R.ok(brand);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody PmsBrand brand ){

        boolean save = pmsBrandService.save(brand);

        return  R.ok(save);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable String id){

        boolean remove = pmsBrandService.removeById(id);

        return  R.ok(remove);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody PmsBrand brand){

        boolean save = pmsBrandService.updateById(brand);

        return  R.ok(save);
    }
}

